﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Controller;
using Entity;

namespace Web
{
    public partial class CheckInventory : System.Web.UI.Page
    {
        Helper helper = new Helper();
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                ProductController pc = new ProductController();
                IList<ProductEntity> productEntities = pc.FindAllProductEntities();
                ProductGridView.DataSource = productEntities;
                ProductGridView.DataBind();
            }
            this.PreRender += new EventHandler(UpdateFlashMessage);
        }
        private void UpdateFlashMessage(object sender, EventArgs e)
        {
            helper.ShowFlashMessage(FlashMessageLabel);
        }

        protected void ProductGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            ProductGridView.PageIndex = e.NewPageIndex;
            ProductController pc = new ProductController();
            IList<ProductEntity> productEntities = pc.FindAllProductEntities();
            ProductGridView.DataSource = productEntities;
            ProductGridView.DataBind();
        }

        protected void SearchButton_Click(object sender, EventArgs e)
        {
            string keyword = SearchTextBox.Text.Trim();
            ProductController productController=new ProductController();
            IList<ProductEntity> productEntities = productController.FindProductByKeyword(keyword);
            ProductGridView.DataSource = productEntities;
            ProductGridView.DataBind();
        }
    }
}